import javax.imageio.plugins.tiff.ExifInteroperabilityTagSet;

class Animal {
    String name;
    int age;
    public Animal(String name,int age) {
        this.name = name;
        this.age = age;
    }
    public void eat() {
        System.out.println(name + "正在吃饭");
    }

    public void sleep() {
        System.out.println(name + "正在睡觉");
    }
}

// Dog.java
 class Dog extends Animal {
    public Dog(String name,int age) {
        super(name,age);
    }

    void bark() {
        System.out.println(name + "汪汪汪");
    }

    public void eat() {
        System.out.println(name + "正在吃狗粮...");
    }

    @Override
    public void sleep() {
        System.out.println("Dog::sleep()");
    }
}

// Cat.java
 class Cat extends Animal {
    public Cat(String name,int age) {
        super(name,age);
    }

    void mew() {
        System.out.println(name + "喵喵喵");
    }
}

class Base {
     int a;
     int b;
     int c;
     public Base() {
         System.out.println("Base()");
     }
    public void methodA(){
     System.out.println("Base中的methodA()");
   }

   public void methodB() {
       System.out.println("Base中的methodB()");
   }

    public int getA() {
        return a;
    }

    public int getB() {
        return b;
    }

}

class Derive extends Base {
    int a;
    char b;


    public Derive() {
        super();
        System.out.println("Derive()");
    }
    public void method() {
        a = 100;
        b = 101;
        c = 102;
    }

    public void methodB(){
        System.out.println("Derive中的methodA()");
    }

    public void methodC(){
       a = 100;
       b = 101;

       super.a = 200;
       super.b = 201;

       methodA();
       methodB();
       super.methodB();
    }

}

class Person {
    String name;
    int age;

    public Person() {
        this.name = name;
        this.age = age;
        System.out.println("Person()构造方法执行");
    }

    {
        System.out.println("Person()实例方法执行");
    }

    static {
        System.out.println("Person()静态代码块执行");
    }
}

class Student extends Person{
    public Student() {
        System.out.println("Student()构造方法执行");
    }

    {
        System.out.println("Student()实例方法执行");
    }

    static {
        System.out.println("Student()静态代码块执行");
    }
}

public class Test {
    public static void main(String[] args) {
//        Derive derive = new Derive();
        // 会先执行静态方法，然后执行父类的实例方法，最后是构造，再是子类
        // 静态方法只会被执行一次
        Student s = new Student();
        Student s2 = new Student();
    }
    public static void main4(String[] args) {
//        Derive derive = new Derive();
//        derive.method();
//        System.out.println(derive.a);
//        System.out.println(derive.b);
//        System.out.println(derive.c);
//
//        Derive derive1 = new Derive();
//        derive1.methodA();
//        derive1.methodB();
//        derive1.methodC();

        Derive derive = new Derive();
        derive.methodC();
        System.out.println(derive.a);
        System.out.println(derive.b);
        System.out.println(derive.getA());
        System.out.println(derive.getB());
    }
    public static void main3(String[] args) {
        Dog dog = new Dog("asd",123);
        System.out.println(dog.name);
        System.out.println(dog.age);

        Animal animal = new Dog("123",3);
        animal.eat();
    }
//    public static void main2(String[] args) {
//        Dog dog = new Dog();
//        System.out.println(dog.name);
//        System.out.println(dog.age);
//        dog.name = "小黑"; // 为 name 赋值
//        dog.age = 3;      // 为 age 赋值
//        System.out.println(dog.name); // 输出 "小黑"
//        System.out.println(dog.age);  // 输出 3
//
//        dog.eat();  // 输出 "小黑正在吃饭"
//        dog.bark(); // 输出 "小黑汪汪汪"
//
//        Cat cat = new Cat();
//        cat.name = "小白"; // 为 name 赋值
//        cat.age = 2;      // 为 age 赋值
//        System.out.println(cat.name); // 输出 "小白"
//        System.out.println(cat.age);  // 输出 2
//
//        cat.eat(); // 输出 "小白正在吃饭"
//        cat.mew(); // 输出 "小白喵喵喵"
//    }

//    static int i = 0;
//    int m = 12;
//    public int aMethod() {
//        i++;
//        return i;
//    }
//    public static void main1(String[] args) {
//        Test test = new Test();
//        test.aMethod();
//        int j = test.aMethod();
//        System.out.println(j);
//        test.m = 13;
//        System.out.println(test.m);
//    }
}
